package com.qzsoft.zhjd.asphalt.modules.asphaltqualitystatistics.dto;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.qzsoft.jeemis.common.annotation.Dict;

import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName AsphaltQualityStatisticsDto
 * @Description 沥青质量汇总分析控制器
 * @author linhuawei
 * @since 2021-08-10
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
public class AsphaltQualityStatisticsDto {

    /**
     * 拌合楼
     *
     * @return
     */
    @Excel(name = "拌合楼", width = 40)
    private String stationName;

    /**
     * 级配类型
     */
    @Excel(name = "配方类型", width = 20)
    private String matchType;

    /**
     * 配方名称
     */
    @Excel(name = "配方名称", width = 20)
    private String matchName;

    /**
     * 配方编号
     */
    @Excel(name = "配方编号", width = 20)
    private String matchCode;

    /**
     * 项目名称
     */
    @Excel(name = "项目名称", width = 40)
    private String projectName;

    /**
     * 摊铺层级
     */
    private String pavingLevel;

    /**
     * 摊铺层级
     */
    @Dict(dicCodeField = "pavingLevel", dictCodeId = "PAVING_LEVEL")
    @Excel(name = "摊铺层级", width = 16)
    private String pavingLevelLabel;

    /**
     * 生产批次
     */
    @Excel(name = "已生产批次", width = 16, type = 10)
    private Integer number;

    /**
     * 重量
     */
    @Excel(name = "已生产重量(吨)", width = 16, type = 10)
    private BigDecimal weight;

    /**
     * 平均油石比
     */
    @Excel(name = "平均油石比", width = 16, type = 10)
    private BigDecimal asphaltAggregateRatioAvg;

    /**
     * 设计油石比
     */
    @Excel(name = "设计油石比", width = 16, type = 10)
    private BigDecimal asphaltAggregateRatio;

    /**
     * 平均温度
     */
    @Excel(name = "平均温度", width = 16, type = 10)
    private BigDecimal temperatureAvg;

    /**
     * 设计温度
     */
    @Excel(name = "设计温度", width = 16, type = 10)
    private String temperature;

    /**
     * 最大温度
     */
    private BigDecimal temperatureMax;

    /**
     * 最小温度
     */
    private BigDecimal temperatureMin;

    /**
     * 不合格重量
     */
    @Excel(name = "不合格重量(吨)", width = 16, type = 10)
    private BigDecimal alarmWeight;

    /**
     * 不合格批次
     */
    @Excel(name = "不合格批次", width = 16, type = 10)
    private Integer alarmNumber;

    /**
     * 温度预警数量
     */
    private Integer temperatureAlarm;

    /**
     * 温度预警比例
     */
    private BigDecimal temperatureAlarmRatio;

    /**
     * 油石比预警数量
     */
    private Integer asphaltAggregateRatioAlarm;

    /**
     * 油石比预警比例
     */
    private BigDecimal asphaltAggregateRatioAlarmRatio;

    /**
     * 筛孔预警数量
     */
    private Integer sieveAlarm;

    /**
     * 筛孔预警比例
     */
    private BigDecimal sieveAlarmRatio;

    public String getTemperature() {
        String max = null == temperatureMax ? "0" : temperatureMax.stripTrailingZeros().toEngineeringString();
        String min = null == temperatureMin ? "0" : temperatureMin.stripTrailingZeros().toEngineeringString();
        if("0".equals(min) && "0".equals(max)) {
            return null;
        }
        if("0".equals(min) && !"0".equals(max)) {
            return max;
        }
        if(!"0".equals(min) && "0".equals(max)) {
            return min;
        }
        if (max.equals(min)) {
            return max;
        }
        return min + "~" + max;
    }

    public BigDecimal getTemperatureAlarmRatio() {
        if (null == number || 0 == number || null == temperatureAlarm || 0 == temperatureAlarm) {
            temperatureAlarmRatio = BigDecimal.ZERO;
        } else {
            temperatureAlarmRatio = new BigDecimal(temperatureAlarm * 100).divide(new BigDecimal(number), 2,
                    RoundingMode.HALF_UP);
        }
        return temperatureAlarmRatio;
    }

    public BigDecimal getAsphaltAggregateRatioAlarmRatio() {
        if (null == number || 0 == number || null == asphaltAggregateRatioAlarm || 0 == asphaltAggregateRatioAlarm) {
            asphaltAggregateRatioAlarmRatio = BigDecimal.ZERO;
        } else {
            asphaltAggregateRatioAlarmRatio = new BigDecimal(asphaltAggregateRatioAlarm * 100)
                    .divide(new BigDecimal(number), 2, RoundingMode.HALF_UP);
        }
        return asphaltAggregateRatioAlarmRatio;
    }

    public BigDecimal getSieveAlarmRatio() {
        if (null == number || 0 == number || null == sieveAlarm || 0 == sieveAlarm) {
            sieveAlarmRatio = BigDecimal.ZERO;
        } else {
            sieveAlarmRatio = new BigDecimal(sieveAlarm * 100).divide(new BigDecimal(number), 2, RoundingMode.HALF_UP);
        }
        return sieveAlarmRatio;
    }

}
